using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using System;

namespace DDZ
{
    public static class SystemHelper
    {
        public static readonly DateTime enter_time = DateTime.UtcNow;
        static TimeSpan GetLocalToUtc()
        {
            TimeSpan temp = DateTime.Now - DateTime.UtcNow;
            int hours = (int)(temp.Days * 24 + temp.Hours + 0.5 + temp.Minutes / 60.0);
            return new TimeSpan(hours, 0, 0);
        }
        public static readonly TimeSpan LocalToUtc = GetLocalToUtc();
        public static readonly DateTime Utc1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        public static readonly DateTime Local1970 = Utc1970.Add(LocalToUtc);
        public const long Tick1970 = 621355968000000000;
        public static double SecondToTicks(long sec)
        {
            return sec * TimeSpan.TicksPerSecond;
        }
        public static double TicksToSecond(long Ticks)
        {
            return Ticks / TimeSpan.TicksPerSecond;
        }
        // 将距离 [UTC 1970年1月1日 0:00:00] 的秒数 转为本地标准时间
        public static DateTime SecondToDateTime(long sec)
        {
            return new DateTime(Local1970.Ticks + TimeSpan.TicksPerSecond * sec, DateTimeKind.Utc);
        }
        public static double DateTimeToSecond(DateTime res)
        {
            return TicksToSecond(res.Ticks - Local1970.Ticks);
        }
        public static double now()
        {
            DateTime tmp = DateTime.UtcNow;
            return (double)tmp.Ticks / (double)TimeSpan.TicksPerSecond;
        }
        public static void TraversalString(string text, UnityAction<int, int> cb)
        {
            for (int i = 0, len = text.Length; i < len; ++i)
            {
                cb(i, (int)text[i]);
            }
        }
        public static void GetCharacterInfos(UnityEngine.Font font, string text, UnityAction<int, UnityEngine.CharacterInfo> cb)
        {
            font.RequestCharactersInTexture(text);
            UnityEngine.CharacterInfo ch = new UnityEngine.CharacterInfo();
            for (int i = 0, len = text.Length; i < len; ++i)
            {
                font.GetCharacterInfo(text[i], out ch);
                cb(i, ch);
            }
        }
        public static double elapsedtime()
        {
            return (double)(DateTime.UtcNow.Ticks - enter_time.Ticks) / (double)TimeSpan.TicksPerSecond;
        }
        /// Svn忽略该字段,任意覆盖
        private const string build_info = "2021-04-21 20:13:07Z";
        private const long build_time = 1619035987;
        public static string getBuildInfo()
        {
            return build_info;
        }
        public static long getBuildTime()
        {
            return build_time;
        }
        public static bool isEditorPaused
        {
            get
            {
#if UNITY_EDITOR
                return UnityEditor.EditorApplication.isPaused;
#else
                return false;
#endif
            }
            set
            {
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPaused = value;
#endif
            }
        }
    }
}